package com.example.demo.Utils;

import lombok.Data;

/**
 * @Author: lu
 * @Date: 2024-08-29-18:43
 * @Description:
 */
@Data
public class Result<T> {
    /**
     * 默认成功
     */
    private  String msg = "SUCCESS";


    /**
     * 默认正常
     */
    private  Integer code = 200;


    /**
     * 使用泛型封装
     */
    private  T data;


    /**
     * 时间戳
     */
    private  long timestamp  = System.currentTimeMillis();

    /**
     * 初始化构造方法
     * @param data
     */
    public Result(T data) {
        this.data = data;
    }

    public Result(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    /**
     * 定义静态构造方法，并将data封装给前端
     */

    public  static <T> Result success(){
        return new Result("请求成功");
    }


    public static <T>  Result success(T data){
        return new Result(data);
    }

    public static  <T> Result error(String msg){
        return new Result(msg,400,"错误");
    }

}